var express = require('express')
var router = express.Router()
var userService = require('./service/service')
// post 登录
router.post('/login', (req, res) => {
	userService.findUser({
		level: req.body.level,
		userName: req.body.username,
		userPwd: req.body.password
	}, response => {
		res.send(response)
	})
})
router.post('/shiyan',(req, res) => {
	console.log('a')
	console.log(req.body)
})
// 注册查询邀请码
router.post('/preInvite', (req, res) => {
	userService.preInvite(req.body, response => {
		res.send(response)
	})
})
// post 注册查询昵称
router.post('/preRegister', (req, res) => {
	// console.dir('req:4' + req.body.username)
	// console.log(data)
	userService.preRegister(req.body, response => {
		res.send(response)
	})
})
// 注册
router.post('/register', (req, res) => {
	var data = {
		userName: req.body.username,
		userPwd: req.body.password,
		level: req.body.level
	}
	userService.register(data, response => {
		res.send(response)
	})
})
// 获取用户基本信息
router.post('/getuserInfo', (req, res) => {
	var data = {
		userName: req.body.username
	}
	userService.getuserInfo(data, response => {
		res.send(response)
	})
})
//获取版块
router.get('/getcollege', (req, res) => {
	userService.getcollege(response => {
		res.send(response)
	})
})
router.post('/editcollege', (req, res) => {
	userService.editcollege(req.body, response => {
		res.send(response)
	})
})
// 删除版块
router.delete('/getcollege/:id', (req, res) => {
	userService.deletecollege(req.params.id, response => {
		res.send(response)
	})
})
//主页获取帖子信息
router.get('/getpostinfo/:id', (req, res) => {
	userService.getpostInfo({ collegeId: req.params.id }, response => {
		res.send(response)
	})
})
//获取指定帖子信息
router.get('/getappointPost/:id', (req, res) => {
	userService.getappointPost(req.params.id, response => {
		res.send(response)
	})
})
// 发布帖子
router.post('/sendPost', (req, res) => {
	userService.sendPost(req.body, response => {
		res.send(response)
	})
})
// 修改帖子的阅读量和点赞量
router.post('/updatePost', (req, res) => {
	userService.updatePost(req.body, response => {
		res.send(response)
	})

})
// 提交评论
router.post('/sendComment', (req, res) => {
	// console.log(req.body)
	userService.sendComment(req.body, response => {
		res.send(response)
	})
})
// 获取评论
router.get('/getcomment', (req, res) => {
	// console.log(req.params.id)
	userService.getcomments(req.query, response => {
		res.send(response)
	})
})
// 获取帖子全部信息
router.post('/getpostall', (req, res) => {
	userService.getpostAll(req.body.username, function (response) {
		res.send(response)
	})
})
// 查询私信空间
router.post('/getupRoom', (req, res) => {
	userService.getupRoom(req.body, (response) => {
		// console.log(response)
		res.send(response)
	})
})
// 创建空间
router.post('/setupRoom', (req, res) => {
	userService.setupRoom(req.body, (response) => {
		res.send(response)
	})
})
//删除空间
router.delete('/deleteRoom/:id', (req, res) => {
	userService.deleteRoom(req.params.id, function (response) {
		res.send(response)
	})
})
// 发送私信
router.post('/sendContent', (req, res) => {
	userService.sendContent(req.body, (response) => {
		res.send(response)
	})
})
// 获取消息
router.post('/getContent', (req, res) => {
	userService.getContent(req.body, (response) => {
		// console.log(response)
		res.send(response)
	})
})
// 修改资料
router.post('/editDetail', (req, res) => {
	userService.editDetail(req.body, (response) => {
		res.send(response)
	})
})
// 关注
router.post('/follow', (req, res) => {
	userService.follow(req.body, response => {
		res.send(response)
	})
})
// 个人中心获取全部回复
router.post('/getpostReplies', (req, res) => {
	userService.getpostReplies(req.body, response => {
		res.send(response)
	})
})
// 后台数据查询
// 查询用户
router.get('/users/:id', (req, res) => {
	userService.getuser(req.params.id, response => {
		res.send(response)
	})
})
// 删除用户
router.delete('/deleteuser/:username', (req, res) => {
	userService.deleteuser(req.params.username, response => {
		res.send(response)
	})
})
// 查询帖子
router.get('/postinfo/:type', (req, res) => {
	userService.getpostInfo({ type: req.params.type }, response => {
		// console.log(response)
		res.send(response)
	})
})
// 删除帖子
router.delete('/postinfo/:id', (req, res) => {
	userService.deletePost(req.params.id, response => {
		// console.log(response)
		res.send(response)
	})
})
// 修改帖子的类型
router.post('/typeChange', (req, res) => {
	userService.typeChange(req.body, response => {
		// console.log(response)
		res.send(response)
	})
})
// 获取积分信息
router.get('/noticeInfo/:name', (req, res) => {
	userService.noticeInfo(req.params.name, response => {
		res.send(response)
	})
})
// 管理员修改积分信息
router.post('/editnoticeInfo', (req, res) => {
	userService.editnoticeInfo(req.body, response => {
		res.send(response)
	})
})
// 普通用户修改积分
router.post('/editInteg', (req, res) => {
	userService.editInteg(req.body, response => {
		res.send(response)
	})
})
// 将通知未读改为已读
router.post('/noticeRead', (req, res) => {
	// console.log(req.body)
	userService.noticeRead(req.body, response => {
		res.send(response)
	})
})
// 将私信未读改为已读
router.post('/msgRead', (req, res) => {
	userService.msgRead(req.body, response => {
		res.send(response)
	})
})
// 管理员发公告
router.post('/adminNotice', (req, res) => {
	userService.adminNotice(req.body, response => {
		res.send(response)
	})
})
router.post('/inviteInsert', (req, res) => {
	userService.inviteInsert(req.body, response => {
		res.send(response)
	})
})
module.exports = router
